﻿/*
 * Twipler - Twitter Web Client with features.
 *  
 *  Copyright (C) 2010. Ian Quigley
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. 
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Twipler.App.Render.Effect
{
    
    public class Durty
    {
        // This code is quick and dirty for now.
        public static void Render(StringBuilder builder, string tweet)
        {
            foreach (TweetSection section in TweetDecoder.Decode(tweet))
            {
                switch (section.SectionType)
                {
                    case TweetSectionType.NormalText:
                        builder.Append(section.Text);
                        break;
                    case TweetSectionType.AtName:
                        builder.AppendFormat("<a class=\"atname\" href=\"user.html?name={0}\">{1}</a>", section.Text.Substring(1), section.Text);
                        break;
                    case TweetSectionType.HashCode:
                        builder.AppendFormat("<a class=\"hashcode\" href=\"search.html?term={0}\">{1}</a>", HttpUtility.UrlEncode(section.Text), section.Text);
                        break;
                    default:
                		string prefix = string.Empty;
						if (section.Text.ToLower().StartsWith("www."))
							prefix = "http://";

                        builder.AppendFormat("<a class=\"url\" target=\"_blank\" href=\"{0}{1}\">{2}</a>", prefix, section.Text, section.Text);
                        break;
                }
            }

        }

    }
}
